package br.com.petsis.conversores;

import java.text.DecimalFormat;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;


public class ConversorRG implements Converter {

	public Object getAsObject(FacesContext context, UIComponent component, String valorCampo){
		Object valor = null;
		if(valorCampo != null && !valorCampo.equals("")){
			valor = desmacaraValor(valorCampo);
		}
		
		return valor;
	}

	public String getAsString(FacesContext context, UIComponent component, Object objCampo){
		String valor = null;
		if(objCampo != null && !objCampo.toString().equals("")){
			valor = mascaraValor(objCampo.toString());
		}
		return valor;
	}

	public static String mascaraValor(String valor) {
		DecimalFormat df = new DecimalFormat("0");  
		String valorRetorno = df.format(Double.valueOf(valor));  
		return valorRetorno;
	}
	
	public static Float desmacaraValor(String valor) {
		return new Float(valor);
	}
}